package ntd.remote.link;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.log.StaticLog;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.remote.link.bo.MsgBO;
import ntd.remote.online.ComOnline;
import ntd.remote.online.bo.OnlineInfo;

public class ActionRemoteRegister extends ActionAbs {

    public static final String ACTION_REMOTE_REGISTER = "action-remote-register";

    @Override
    public ActionInfo info() {
        return new ActionInfo("客户端-remote-register", ACTION_REMOTE_REGISTER, this);
    }

    @Override
    public ActionOutBo handle() {
        MsgBO msgBO = actionInBo.getData().toBean(MsgBO.class);

        OnlineInfo onlineInfo = ComOnline.getOnlineInfo("appInfo", msgBO.getNetCode());
        if (ObjectUtil.isNull(onlineInfo)) {
            onlineInfo = new OnlineInfo();
        }
        onlineInfo.setName(msgBO.getData());
        onlineInfo.setIp(msgBO.getNetCode());
        onlineInfo.setNettyChannelCode(msgBO.getNetCode());
        onlineInfo.setClientCode(msgBO.getTerminalCode());
        ComOnline.online("appInfo", onlineInfo);
        StaticLog.info("设备[{}:{}:{}]注册成功...", onlineInfo.getIp(), onlineInfo.getClientCode(), onlineInfo.getName());
        return new ActionOutBo();
    }
}
